package org.leetcode.middle.leetcode189;

import java.util.Arrays;

public class Solution {

    public void rotate3(int[] nums, int k) {

        int n = nums.length;

        int[] temp = new int[n];

        for (int i = 0; i < n; i++) {
            temp[(i + k) % n] = nums[i];
        }

        System.arraycopy(temp, 0, nums, 0, n);
    }

    public void rotate2(int[] nums, int k) {

        int n = nums.length;
        int[] newArray = new int[n];

        for (int i = 0; i < n; i++) {
            newArray[(i + k) % n] = nums[i];
        }

        System.arraycopy(newArray, 0, nums, 0, n);
    }

    public void rotate(int[] nums, int k) {
        int length = nums.length;

        if (length > k) k = length % k;

        if (k == 0) return;

        int index = 0;

        int temp = 0;

        while (index == 0) {
            int changeIndex = index + k;

            if (changeIndex >= length) {
                changeIndex = changeIndex - length;
            }

            temp = nums[changeIndex];
            nums[changeIndex] = nums[index];
            nums[index] = temp;
        }


    }

    public static void main(String[] args) {

        int num = 6;

        int k = 3;

        System.out.println(num % k);
    }
}
